﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Quote.DataContent;
using System.Linq;
using Quote.Model;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!Page.IsPostBack)
        //{
        BindData();
        //}
    }

    private void BindData()
    {
        using (QuoteDataContext context = new QuoteDataContext())
        {
            var result = from c in context.PartsInInventory
                         select c;
            this.GridView1.DataSource = result.ToList();
            this.GridView1.DataBind();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        QuoteDataContext context = new QuoteDataContext();
        for (int i = 0; i < 10; i++)
        {
            PartInInventory part = new PartInInventory() { ID = i, FullName = "Full Name of " + i.ToString(), SerialNo = Guid.NewGuid().ToString() };
            context.PartsInInventory.Add(part);
        }
        context.SaveChanges();
        context.Dispose();
        BindData();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        QuoteDataContext context = new QuoteDataContext();
        var res = context.PartsInInventory.Take(10);
        foreach (var entity in res)
        {
            context.PartsInInventory.Remove(entity);
        }
        context.SaveChanges();
        BindData();
    }
}